package cs341.group2.mycontacts;

import java.util.ArrayList;
import java.util.HashMap;

import cs341.group2.mycontacts.Database.MyContactsDB;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;

public class CategoryButtonAdapter extends BaseAdapter {
    private Context mContext;
    private MyContactsDB myContactsDb;
    private ArrayList<HashMap<String, String>> items;

    public CategoryButtonAdapter(Context context, ArrayList<HashMap<String, String>> items) {
    	mContext = context;
    	myContactsDb = new MyContactsDB(mContext);
        this.items = items;

    }
    
    // Declare button click listener variable
    private OnClickListener mOnButtonClick;

    // Method to set button click listener variable
    public void setOnButtonClickListener(OnClickListener listener) {
        mOnButtonClick = listener;
    }

    public CategoryButtonAdapter(Context c) {
        mContext = c;
    }

    public int getCount() {
        return items.size();
    }

    public Object getItem(int position) {
        return items.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View view, ViewGroup parent) {
	   LayoutInflater inflater = LayoutInflater.from(parent.getContext());
	   view = inflater.inflate(R.layout.category_list, parent, false);
       
       HashMap<String, String> item = items.get(position);
       
       final Button category = (Button)view.findViewById(R.id.categoryName);
       category.setText(item.get("categoryName"));
       category.setHeight(100);
       category.setId(Integer.parseInt(item.get("categoryId")));
       
       //on click for remove from category button
       category.setOnClickListener(new View.OnClickListener() {
		
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(mContext, ViewCategory.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				intent.putExtra("Name", category.getText());
				intent.putExtra("Id", category.getId());
				mContext.startActivity(intent);
			}
		});
       
       return view;
       
    }

}